const util = require('../../utils/util.js');

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    locName: String,
    type: String,
    key: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    locName: '',
    latitude: '',
    longitude: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getLocation: function () {
      var self = this;
      wx.chooseLocation({
        success: function (res) {
          self.setData({
            locName: res.name,
            latitude: res.latitude,
            longitude: res.longitude
          })
          wx.setStorage({
            key: 'address',
            data: res.name,
          })
          wx.setStorage({
            key: 'latitude',
            data: res.latitude,
          })
          wx.setStorage({
            key: 'longitude',
            data: res.longitude,
          })
        }
      })
    },
    wx_scan: function () {
      util.wx_scan();
    },
    custormerService: function () {
      wx.getStorage({
        key: 'key',
        success: res => {
          wx.navigateTo({
            url: '../message_list/message_list'
          })
        },
        fail: () => {
          wx.getSetting({
            success: res => {
              if (res.authSetting['scope.userInfo']) {
                wx.navigateTo({
                  url: '../chooselogin/chooselogin'
                })
              } else {
                wx.navigateTo({
                  url: '../login/login'
                })
              }
            }
          })
        }
      })
    },
  }
})